package leetcode;


import java.util.PriorityQueue;

public class LC215KthLargestNumber {

    public int findKthLargest(int[] nums, int k) {
        PriorityQueue<Integer> priorityQueue = new PriorityQueue<>(k);
        for (int i = 0; i < k; i++) {
            priorityQueue.offer(nums[i]);
        }
        for (int i = k; i < nums.length; i++) {
           if (nums[i] > priorityQueue.peek()) {
               priorityQueue.poll();
               priorityQueue.offer(nums[i]);
           }
        }
        return priorityQueue.peek();
    }


}
